package com.yunkeji.admin.controller.pay;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.yunkeji.common.annotation.Log;
import com.yunkeji.common.annotation.RepeatSubmit;
import com.yunkeji.common.core.controller.BaseController;
import com.yunkeji.common.core.domain.PageQuery;
import com.yunkeji.common.core.domain.R;
import com.yunkeji.common.core.page.TableDataInfo;
import com.yunkeji.common.core.validate.AddGroup;
import com.yunkeji.common.core.validate.EditGroup;
import com.yunkeji.common.enums.BusinessType;
import com.yunkeji.common.utils.poi.ExcelUtil;
import com.yunkeji.dao.vo.PayWithdrawPlanVo;
import com.yunkeji.system.domain.bo.PayWithdrawPlanBo;
import com.yunkeji.system.service.IPayWithdrawPlanService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 充值方案
 *
 * @author yunkeji
 * @date 2024-09-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/payWithdrawPlan")
public class PayWithdrawPlanController extends BaseController {

    private final IPayWithdrawPlanService iPayWithdrawPlanService;

    /** 查询充值方案列表 */
    @SaCheckPermission("system:payWithdrawPlan:list")
    @GetMapping("/list")
    public TableDataInfo<PayWithdrawPlanVo> list(PayWithdrawPlanBo bo, PageQuery pageQuery) {
        return iPayWithdrawPlanService.queryPageList(bo, pageQuery);
    }

    /** 导出充值方案列表 */
    @SaCheckPermission("system:payWithdrawPlan:export")
    @Log(title = "充值方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PayWithdrawPlanBo bo, HttpServletResponse response) {
        List<PayWithdrawPlanVo> list = iPayWithdrawPlanService.queryList(bo);
        ExcelUtil.exportExcel(list, "充值方案", PayWithdrawPlanVo.class, response);
    }

    /**
     * 获取充值方案详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:payWithdrawPlan:query")
    @GetMapping("/{id}")
    public R<PayWithdrawPlanVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iPayWithdrawPlanService.queryById(id));
    }

    /** 新增充值方案 */
    @SaCheckPermission("system:payWithdrawPlan:add")
    @Log(title = "充值方案", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PayWithdrawPlanBo bo) {
        return toAjax(iPayWithdrawPlanService.insertByBo(bo));
    }

    /** 修改充值方案 */
    @SaCheckPermission("system:payWithdrawPlan:edit")
    @Log(title = "充值方案", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PayWithdrawPlanBo bo) {
        return toAjax(iPayWithdrawPlanService.updateByBo(bo));
    }

    /**
     * 删除充值方案
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:payWithdrawPlan:remove")
    @Log(title = "充值方案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iPayWithdrawPlanService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
